<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body{
            padding-bottom: 800px;
            padding-left: 30px;
        }
        .list-item{
            background-color: #dedede;
            width: 400px;
            margin: 4px 0px;
            padding: 4px;
            display: flex;
            flex-flow: row nowrap;
            justify-content: space-between;
        }
    </style>
</head>
<body>
    <div id="app">
        <p>arr:{{ arr }}</p>
        <my-list :data="arr" #="{ row,$index }">
            <span style="color:red">{{ row.lable }}</span>
            <input type="text" v-model="row.lable">
            <input type="button" value="删除" @click="removeItem($index)">
        </my-list>
    </div>

    <script type="text/x-template" id="myList">
        <ul>
            <li class="list-item" v-for="(row,i) in data">
                <slot :row="row" :$index="i"></slot>
            </li>
        </ul>
    </script>

    <script type="module">
        // 加载 Vue3 的ESM 模块文件
        import { createApp } from "../../assets/vue3/vue.esm-browser.js"
        const MyList = {
            template:"#myList",
            props: {
                data: {
                    type: Array,
                    default(){
                        return []
                    }
                },
            },
        }
        createApp({
            components: {
                MyList,
            },
            data(){
                return {
                    arr:[
                        { lable:"元素1" },
                        { lable:"元素2" },
                        { lable:"元素3" },
                        { lable:"元素4" },
                        { lable:"元素5" },
                    ]
                }
            },
            methods: {
                removeItem(i) {
                    this.arr.splice(i,1)
                }
            },
        }).mount("#app")
    </script>
</body>
</html>